import wx
from tabber import *

defaultTabs = 'Tab 1\nTab 2\nTab 3\nTab 4\nTab 5'

# Combo Box Options
textOptions = {
                'face':         [ 'Helvetica', 'Times-New Roman' ],
                'style':        [ 'Regular', 'Bold', 'Italic', 'Bold-Italic' ],
                'size':         [ '9', '10', '11', '12', '13', '14', '15', '16', '17', '18' ],
                'leading':      [ 'Auto', ],
                'color':        [ 'Black', 'Gray', 'Red', 'Green', 'Blue' ],
                'orientation':  [ 'Text-In', 'Text-Out', 'Vertical' ]
                }

tabOptions = {
                'size':         [ '9"x11"', '8.5"x11"' ],
                'num':          [ '5', '10' ],
                'orientation':  [ 'Portrait', 'Landscape' ],
                }


class Frame( wx.Frame ):
    def __init__( self, parent, id, title ):
        wx.Frame.__init__(self, parent, id, title, (-1, -1))
        # Create Panels to Hold Controls
        self.leftPanel = wx.Panel( self, -1, size=(250,200) ) # Holds Tab Text Entry 
        self.rightPanel = wx.Panel( self, -1, size=(250,200) ) # Holds All Options for Text & Tabs

        # Layout Panels Left to Right
        frameSizer = wx.BoxSizer( wx.HORIZONTAL )
        frameSizer.Add( self.leftPanel, 1, wx.EXPAND )
        frameSizer.Add( self.rightPanel, 0, wx.EXPAND )

        # Left Panel Controls:
        self.tabsTextBox = wx.StaticBox( self.leftPanel, -1, 'Tab Text' )
        self.tabsText = wx.TextCtrl( self.leftPanel, -1, defaultTabs, size=(150,250), style=wx.TE_MULTILINE|wx.HSCROLL )
        self.numTabs = wx.StaticText( self.leftPanel, -1, '%d Tabs' % len(self.tabsText.GetValue().split('\n')) )
        # Left Panel Layout:
        leftSizer = wx.BoxSizer( wx.VERTICAL )
        tabTextSizer = wx.StaticBoxSizer( self.tabsTextBox, wx.VERTICAL )
        tabTextSizer.Add( self.tabsText, 1, wx.ALL|wx.EXPAND, 5 )
        tabTextSizer.Add( self.numTabs, 0, wx.LEFT|wx.RIGHT, 5 )
        leftSizer.Add( tabTextSizer, 1, wx.LEFT|wx.TOP|wx.BOTTOM|wx.EXPAND, 15 )
        self.leftPanel.SetSizer( leftSizer )

        # Right Panel
        # Text Options Controls:
        self.textOptionsBox = wx.StaticBox( self.rightPanel, -1, 'Text Options', size=(250,200) )
        self.textFace = wx.ComboBox( self.rightPanel, -1, choices=textOptions['face'], value=textOptions['face'][0] )
        self.textStyle = wx.ComboBox( self.rightPanel, -1, choices=textOptions['style'], value=textOptions['style'][0] )
        self.textSize = wx.ComboBox( self.rightPanel, -1, choices=textOptions['size'], value=textOptions['size'][3] )
        self.textLeading = wx.ComboBox( self.rightPanel, -1, choices=textOptions['leading'], value=textOptions['leading'][0] )
        self.textColor = wx.ComboBox( self.rightPanel, -1, choices=textOptions['color'], value=textOptions['color'][0] )
        self.textOrientation = wx.ComboBox( self.rightPanel, -1, choices=textOptions['orientation'], value=textOptions['orientation'][0] )
        # Text Options Layout:
        textSizer = wx.StaticBoxSizer( self.textOptionsBox, wx.VERTICAL )
        row1 = wx.BoxSizer( wx.HORIZONTAL )
        row2 = wx.BoxSizer( wx.HORIZONTAL )
        row3 = wx.BoxSizer( wx.HORIZONTAL )
        row4 = wx.BoxSizer( wx.HORIZONTAL )
        row5 = wx.BoxSizer( wx.HORIZONTAL )
        row1.Add( self.textFace )
        row2.Add( self.textStyle )
        row3.Add( self.textSize )
        row3.Add( self.textLeading )
        row4.Add( self.textColor )
        row5.Add( self.textOrientation )
        textSizer.Add( row1 )
        textSizer.Add( row2 )
        textSizer.Add( row3 )
        textSizer.Add( row4 )
        textSizer.Add( row5 )
        
        # Tab Options Controls:
        self.tabOptionsBox = wx.StaticBox( self.rightPanel, -1, 'Tab Options', size=(250,200) )
        self.tabSize = wx.ComboBox( self.rightPanel, -1, choices=tabOptions['size'], value=tabOptions['size'][0] )
        self.tabNum = wx.ComboBox( self.rightPanel, -1, choices=tabOptions['num'], value=tabOptions['num'][0] )
        self.tabOrientation = wx.ComboBox( self.rightPanel, -1, choices=tabOptions['orientation'], value=tabOptions['orientation'][0] )
        self.tabPad = wx.CheckBox( self.rightPanel, -1, 'Pad Last Group' )
        self.tabPad.SetValue( True )
        # Tab Options Layout:
        tabSizer = wx.StaticBoxSizer( self.tabOptionsBox, wx.VERTICAL )
        tabSizer.Add( self.tabSize, 0, wx.BOTTOM, 5 )
        tabSizer.Add( self.tabNum, 0, wx.BOTTOM, 5 )
        tabSizer.Add( self.tabOrientation, 0, wx.BOTTOM, 5 )
        tabSizer.Add( self.tabPad, 0, wx.BOTTOM, 5 )

        # Generate Button
        self.generate = wx.Button( self.rightPanel, -1, 'Tab It' )

        # Right Panel Layout:
        rightSizer = wx.BoxSizer( wx.VERTICAL )
        rightSizer.Add( textSizer, 0, wx.LEFT|wx.RIGHT|wx.TOP, 15)
        rightSizer.Add( tabSizer, 0, wx.LEFT|wx.RIGHT, 15 )
        rightSizer.Add( (-1,-1), 1 )
        rightSizer.Add( self.generate, 0, wx.ALL|wx.ALIGN_BOTTOM|wx.ALIGN_CENTER, 20 )
        self.rightPanel.SetSizer( rightSizer )

        # Binds
        self.generate.Bind( wx.EVT_BUTTON, self.onTabber )

        # Set Frame Sizer & Fit Frame Size
        self.SetSizerAndFit( frameSizer )

    def onTabber( self, event ):
        tabs = self.tabsText.GetValue().split('\n')
        tabber( tabs )


class App(wx.App):
     def OnInit(self):
         frame = Frame(None, -1, 'AutoTabber')
         frame.Show(True)
         return True


if __name__ == '__main__':
    app = App(True)
    app.MainLoop()

